class ImsController < ApplicationController
  layout 'project',:only=>[:index]
  before_filter :check_authorization


   def index
     if @project.channels.empty?
        @channel = @project.channels.new
	@channel.save
     else
        @channel = @project.channels.last
     end
       @chats = @channel.chats.reverse
   end
   def show
     @chat = Chat.find(params[:id])
   end
   def new
   end
   def update
     @chat = @project.channels.last.chats.create(params[:chat])
     # create HTML string to show a message
     content = render_component_as_string :action => 'show', :id => @chat.id, :cur_user_id => @cur_user.id
     # create JS string to add a message on list
     javascript = render_to_string :update do |page|
       page.insert_html :top, 'chat-list', content
       page.visual_effect :highlight, 'chat_item_' + @chat.id.to_s, :duration=> 10
     end
     # push JS to clients listening `shot_chat' channel
     Meteor.shoot 'shot_chat', javascript
     # nothing is rendered
     render :nothing => true
   end

end
